package com.example.wallpaperapp.ui.fragment;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wallpaperapp.R;
import com.example.wallpaperapp.base.BaseFragment;
import com.example.wallpaperapp.ui.activity.Activity_setting;
import com.example.wallpaperapp.ui.activity.ChoicenessActivity;
import com.example.wallpaperapp.ui.activity.CollectActivity;
import com.example.wallpaperapp.ui.activity.DownloadActivity;
import com.example.wallpaperapp.ui.activity.FeedbackActivity;
import com.example.wallpaperapp.ui.activity.HistoryActivity;
import com.example.wallpaperapp.ui.activity.LocalActivity;
import com.example.wallpaperapp.ui.activity.LoginActivity;
import com.example.wallpaperapp.ui.activity.MainPagerActivity;
import com.example.wallpaperapp.ui.activity.NowuseActivity;
import com.example.wallpaperapp.utils.CacheDataManager;
import com.example.wallpaperapp.utils.IntentUtil;
import com.example.wallpaperapp.utils.SpfUtils;
import com.example.wallpaperapp.widget.CircleImageView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;

public class MineFragment extends BaseFragment implements View.OnClickListener {
    private LinearLayout lin_collect;
    private LinearLayout lin_history;
    private LinearLayout lin_download;
    private LinearLayout lin_local;
    private LinearLayout lin_clear,lin_feedback,lin_nowuse,lin_mainpager;
    private RelativeLayout toLogIn,toLogIn2;
    private CircleImageView circleImageView;
    private TextView userName;
    private ImageView setting;

    @Override
    protected void initView(View view) {
        setting = view.findViewById(R.id.imv_setting);
        lin_collect = view.findViewById(R.id.lin_collect);
        lin_history = view.findViewById(R.id.lin_history);
        lin_download = view.findViewById(R.id.lin_download);
        lin_local = view.findViewById(R.id.lin_local);
        lin_clear=view.findViewById(R.id.lin_clear);
        lin_feedback=view.findViewById(R.id.lin_feedback);
        lin_nowuse=view.findViewById(R.id.lin_nowuse);
        lin_mainpager=view.findViewById(R.id.lin_mainpager);
        toLogIn = view.findViewById(R.id.toLogIn);
        toLogIn2 = view.findViewById(R.id.toLogIn2);
        circleImageView = view.findViewById(R.id.user_avari2);
        userName = view.findViewById(R.id.userName);
        setOnclick();
    }

    private void setOnclick() {
        //获取本地存储的用户id
        SpfUtils.init(getActivity());
        int a= (int) SpfUtils.getParam("userId",0);
//        if (a==0){
//            toLogIn2.setVisibility(View.GONE);
//            toLogIn.setVisibility(View.VISIBLE);
//        }else {
//            toLogIn.setVisibility(View.GONE);
//            toLogIn2.setVisibility(View.VISIBLE);
//        }
        Log.e(TAG, "setOnclick: "+a);
        lin_collect.setOnClickListener(this);
        lin_history.setOnClickListener(this);
        lin_download.setOnClickListener(this);
        lin_local.setOnClickListener(this);
        lin_clear.setOnClickListener(this);
        lin_feedback.setOnClickListener(this);
        lin_nowuse.setOnClickListener(this);
        lin_mainpager.setOnClickListener(this);
        toLogIn.setOnClickListener(this);
        setting.setOnClickListener(this);
    }
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void initData(Context context) {
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.lin_collect:
                IntentUtil.startActivity(CollectActivity.class, getActivity());
                break;
            case R.id.lin_history:
                IntentUtil.startActivity(HistoryActivity.class, getActivity());
                break;
            case R.id.lin_download:
                IntentUtil.startActivity(DownloadActivity.class, getActivity());
                break;
            case R.id.lin_local:
                IntentUtil.startActivity(LocalActivity.class, getActivity());
                break;
            case R.id.lin_clear:
                    CacheDataManager.clearAllCache(getActivity());
                    Toast.makeText(getContext(), "成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.lin_feedback:
                IntentUtil.startActivity(FeedbackActivity.class, getActivity());
                break;
                case R.id.lin_nowuse:
                IntentUtil.startActivity(NowuseActivity.class, getActivity());
                break;
            case R.id.lin_mainpager:
                IntentUtil.startActivity(MainPagerActivity.class, getActivity());
                break;
            case R.id.toLogIn:
                IntentUtil.startActivity(LoginActivity.class, getActivity());
                break;
            case R.id.imv_setting:
                IntentUtil.startActivity(Activity_setting.class, getActivity());
                break;
        }
    }
}